﻿using Abide_AddOn_API;
using System;
using System.Windows.Forms;

namespace Abide.Forms
{
    public partial class TypeEditorWizard : Form
    {
        public ITypeEditor[] TypeEditors
        {
            get;
            set;
        }

        public TypeEditorWizard()
        {
            InitializeComponent();
        }
        private void TypeEditorWizard_Load(object sender, EventArgs e)
        {
            //Load
            foreach (ITypeEditor editor in TypeEditors)
                foreach(FileAssociation association in editor.Associations)
                {
                    //Create Control
                    Abide.Controls.TypeElement tElement = new Controls.TypeElement();
                    tElement.Association = association;
                    typeEditorsContainer.Controls.Add(tElement);
                }

            //Enable
            installButton.Enabled = true;
        }
        private void installButton_Click(object sender, EventArgs e)
        {
            //Loop through each
            foreach(var control in typeEditorsContainer.Controls)
            {
                if (control is Abide.Controls.TypeElement)
                {
                    var typeElement = control as Abide.Controls.TypeElement;
                    if (typeElement.Registration == Abide.Controls.RegistrationType.Register)
                        Classes.Registration.RegisterType(typeElement.Association);
                    else
                        Classes.Registration.UnregisterType(typeElement.Association);
                }
            }
        }
    }
}
